package com.hundsun.cprs.yyt.service.goods.service.impl;

import com.hundsun.cprs.yyt.common.base.BaseService;
import com.hundsun.cprs.yyt.service.goods.dao.GoodsWithPlateDao;
import com.hundsun.cprs.yyt.service.goods.domain.GoodsWithPlate;
import com.hundsun.cprs.yyt.service.goods.service.GoodsWithPlateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsWithPlateServiceImpl extends BaseService implements GoodsWithPlateService {
    @Autowired
    private GoodsWithPlateDao goodsWithPlateDao;

    @Override
    public void deleteByPrimaryKey(Integer id) {
        goodsWithPlateDao.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(GoodsWithPlate record) {
        goodsWithPlateDao.insert(record);
    }

    @Override
    public List<GoodsWithPlate> selectGoodsWithPlate(GoodsWithPlate goodsWithPlate) {
        return goodsWithPlateDao.selectGoodsWithPlate(goodsWithPlate);
    }

    @Override
    @Transactional
    public void deleteByAreaCodeAndGoodsId(String areaCode, Integer goodsId) {
        GoodsWithPlate data = new GoodsWithPlate();
        data.setAreaCode(areaCode);
        data.setGoodsId(goodsId);
        List<GoodsWithPlate> goodsWithPlateList = selectGoodsWithPlate(data);
        if (!goodsWithPlateList.isEmpty()) {
            for (GoodsWithPlate item : goodsWithPlateList) {
                deleteByPrimaryKey(item.getId());
            }
        }
    }
}
